package com.xmkj.bearuser.home;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.util.SparseArray;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.rxbus.RxBus;
import com.common.rxbus.postevent.RxKeyEvent;
import com.common.utils.EmptyUtils;
import com.xmkj.bearuser.R;
import com.xmkj.bearuser.home.adapter.SearhPagerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Create by leo
 * 创建日期：2018/7/27
 * 描述：
 */

public class BearSearhActivity extends BaseMvpActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_menber_title)
    TextView tvMenberTitle;
    @BindView(R.id.iv_search)
    ImageView ivSearch;
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.rl_search)
    RelativeLayout rlSearch;
    @BindView(R.id.tv_search)
    TextView tvSearch;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    SparseArray<String> titles = new SparseArray<>();
    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_search_bear;
    }

    @Override
    protected void onViewCreated() {
        initTab();
    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(tvSearch);
        attachClickListener(ivBack);

    }

    @Override
    protected void onViewClicked(View view) {
        if(view.getId()==tvSearch.getId()){
            if(EmptyUtils.isEmpty(getEditTextStr(etContent))){
                showToastMsg("请输入搜索内容");
                return;
            }
            RxBus.getDefault().postSticky(new RxKeyEvent(RxKeyEvent.SEARCH_KEY, getEditTextStr(etContent)));
        }else if(view.getId()==ivBack.getId()){
            onBackPressed();
        }
    }

    private void initTab() {
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        viewPager.setOffscreenPageLimit(4);
        titles.append(0, "综合");
        titles.append(1, "价格");
        titles.append(2, "热门");
        titles.append(3, "新品");
        viewPager.setAdapter(new SearhPagerAdapter(getSupportFragmentManager(), titles, context));
        tabLayout.setupWithViewPager(viewPager);
    }


    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }
}
